﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.DistributedServices.Core.ErrorHandlers;
using System.ServiceModel;
using Cesave.Domain.PermisosModule.Contracts.RiegoSistemas;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="riegoSistema"></param>
		public void AddRiegoSistema(Domain.PermisosModule.Entities.RiegoSistema riegoSistema)
		{
			try
			{
				IRiegoSistemaService service = IoCFactory.Resolve<IRiegoSistemaService>();
				service.AddRiegoSistema(riegoSistema);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="riegoSistema"></param>
		public void ChangeRiegoSistema(Domain.PermisosModule.Entities.RiegoSistema riegoSistema)
		{
			try
			{
				IRiegoSistemaService service = IoCFactory.Resolve<IRiegoSistemaService>();
				service.ChangeRiegoSistema(riegoSistema);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.RiegoSistema> FindAllRiegoSistemas()
		{
			try
			{
				IRiegoSistemaService service = IoCFactory.Resolve<IRiegoSistemaService>();
				return service.FindAllRiegoSistemas();
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="status"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.RiegoSistema> FindRiegoSistemasByStatus(bool status = true)
		{
			try
			{
				IRiegoSistemaService service = IoCFactory.Resolve<IRiegoSistemaService>();
				return service.FindRiegoSistemasByStatus(status);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		#endregion
	}
}
